package rmioverlay.client;

import rmioverlay.AppInterface;
import rmioverlay.lib.users.User;
import rmioverlay.server.ServerAppInterface;
import java.rmi.RemoteException;
import java.io.*;

public interface ClientAppInterface<T extends ServerAppInterface> extends AppInterface {
	
	/**
	 * Connects and register to the stored server reference
	 * @throws RemoteException if a network issue occurs
	 */
	public void connect()
			throws RemoteException;
	
	/**
	 * Disconnects from the stored server reference
	 * @throws RemoteException if a network issue occurs
	 */
	public void disconnect()
			throws RemoteException;
	
	/**
	 * Provides the stored reference of running ServerApp
	 * @return the reference of the running ServerApp.
	 * @throws RemoteException if a network issue occurs
	 */
	public T getServer() 
			throws RemoteException;
	
	/**
	 * Callback method, defines what happens when receiving a message.
	 * @param pData The received message
	**/
	public abstract <U>void receive(U pData)
			throws RemoteException;
	
	/**
	 * @param pData
	 * @param pFilename
	 * @param pExt
	 * @throws RemoteException
	 * @throws IOException
	 */
	public void receive(byte[] pData, String pFilename)
			throws RemoteException;
	
	/**
	 * Sents data to all connected clients
	 * @param <T> the type of data which will be sent
	 * @param pData the data to send
	 * @throws RemoteException if a network issue occurs
	 * @throws FileNotFoundException 
	 */
	public <U>void sendAll(U pData)
			throws RemoteException, FileNotFoundException;
	
	/**
	 * Converts a file into an Array of bytes
	 * and sends it to the server
	 * @param f the File to be sent
	 * @throws RemoteException if a network issue occurs
	 */
	 
	public void sendAll(File f)
			throws RemoteException, FileNotFoundException;
	
	/**
	 * Sents data to a connected clients
	 * @param <T> the type of data which will be sent
	 * @param pLogin the login of recipient
	 * @param pData the data to send
	 * @throws RemoteException if a network issue occurs
	 * @throws FileNotFoundException 
	 */
	public <U>void send(String pLogin, U pData)
			throws RemoteException, FileNotFoundException;
	
	/**
	 * Converts a file into an Array of bytes
	 * and sents a file to a connected client
	 * @param pLogin the login of recipient
	 * @param f the file to send
	 * @throws RemoteException if a network issue occurs
	 */
	public void send(String pLogin, File f)
			throws RemoteException, FileNotFoundException;
}
